<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--<button onclick="stop()">停止</button>-->


<script>

//    var worker = new Worker('worker_demo.js');
//    worker.postMessage("Hello World");
//    worker.postMessage({method:'echo',args:['Work']});
//
//
//    worker.onmessage =function (event) {
//        console.log('Received message' +event.data);
//        doSomething();
//    }
//
//    function doSomething() {
//        //执行任务
//        worker.postMessage("Work done!")
//    }
//
//    function stop() {
//        worker.terminate()
//    }
//
//    self.addEventListener('message', function (e) {
//        var data = e.data;
//        switch (data.cmd) {
//            case 'start':
//                self.postMessage('WORKER STARTED: ' + data.msg);
//                break;
//            case 'stop':
//                self.postMessage('WORKER STOPPED: ' + data.msg);
//                self.close(); // Terminates the worker.
//                break;
//            default:
//                self.postMessage('Unknown command: ' + data.msg);
//        };
//    }, false);
function calculate(){
    var ret = 0;
    for(var i = 1; i <= 1e9; i++){
        ret += i;
    }
    return ret;
}
var result;
var start;
var end;
start = +new Date();
result = calculate();
end = +new Date();
console.log(result); //500000000067109000
console.log(end - start); //977

</script>
</body>
</html>